import java.util.*;
/**
public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}
*/
public class Solution {

    public void dfs(TreeNode node, int num, Stack<Integer> temp, ArrayList<ArrayList<Integer>> arr) {
        if (node == null)
            return ;

        temp.push(node.val);

        if (node.left == null && node.right == null && node.val == num)
            arr.add(new ArrayList<>(temp));

        dfs(node.left, num - node.val, temp, arr);
        dfs(node.right, num - node.val, temp, arr);
        
        temp.pop();
    }

    public ArrayList<ArrayList<Integer>> FindPath(TreeNode root,int expectNumber) {
        ArrayList<ArrayList<Integer>> ret = new ArrayList<>();
        Stack<Integer> temp = new Stack<>();

        if (root == null) 
            return ret;

        dfs(root, expectNumber, temp, ret);

        return ret;
    }
}